import { createSlice, PayloadAction } from '@reduxjs/toolkit';

interface ModuleState {
    num: number;
}

const initialState: ModuleState = {
    num: 0,
};

const moduleSlice = createSlice({
    name: 'handleMoudle',
    initialState,
    reducers: {
        // 异步增加指定数字
        add(state, action: PayloadAction<number>) {
            state.num += action.payload;
        },
        // 同步加递增
        add2(state, action: PayloadAction<number>) {
            state.num += action.payload;
        },
    },
});

export const { add, add2 } = moduleSlice.actions;
export default moduleSlice.reducer;
